﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using METODESA.Server.Data.METODESA.Entity;

namespace Metodesa.Tools
{
    public class ClientesTools
    {
        public static HtmlTable ListClientes(IList<Cliente> lCliente)
        {
            HtmlTable table=new HtmlTable();

            if (lCliente != null && lCliente.Count != 0)
            {
                HtmlTableRow r = new HtmlTableRow();
                HtmlTableCell edit = new HtmlTableCell();
                HtmlTableCell delete = new HtmlTableCell();
                HtmlTableCell id = new HtmlTableCell();
                HtmlTableCell name = new HtmlTableCell();
                HtmlTableCell ci = new HtmlTableCell();
                HtmlTableCell address = new HtmlTableCell();
                id.BorderColor = edit.BorderColor = delete.BorderColor = name.BorderColor
                                                                         = ci.BorderColor = "#FFFFFF";
                id.BgColor = edit.BgColor = name.BgColor = delete.BgColor = ci.BgColor
                                                                            = address.BgColor = "#a9a9a9";
                delete.Controls.Add(new LiteralControl(""));
                edit.Controls.Add(new LiteralControl(""));
                id.Controls.Add(new LiteralControl("<b>Id</b>"));
                name.Controls.Add(new LiteralControl("<b>Nombre y Apellido</b>"));
                ci.Controls.Add(new LiteralControl("<b>Cédula</b>"));
                address.Controls.Add(new LiteralControl("<b>Dirección</b>"));
                r.Cells.Add(delete);
                r.Cells.Add(edit);
                r.Cells.Add(id);
                r.Cells.Add(name);
                r.Cells.Add(ci);
                r.Cells.Add(address);
                table.Rows.Add(r);
                int i = 0;
                foreach (Cliente cliente in lCliente)
                {
                    i++;
                    r = new HtmlTableRow();
                    id = new HtmlTableCell();
                    name = new HtmlTableCell();
                    ci = new HtmlTableCell();
                    address = new HtmlTableCell();
                    edit = new HtmlTableCell();
                    delete = new HtmlTableCell();
                    id.BorderColor = name.BorderColor = ci.BorderColor = "#FFFFFF";
                    if (i % 2 == 0)
                    {
                        delete.BgColor = id.BgColor = edit.BgColor = name.BgColor = address.BgColor = ci.BgColor = "#E0E9F5";
                    }
                    else
                    {
                        id.BgColor = delete.BgColor = name.BgColor = edit.BgColor = address.BgColor = ci.BgColor = "#D3D3D3";
                    }
                    id.Controls.Add(new LiteralControl(cliente.Id + ""));
                    name.Controls.Add(new LiteralControl(cliente.Apellido + ", " + cliente.Nombre));
                    ci.Controls.Add(new LiteralControl(cliente.CedulaRif));
                    address.Controls.Add(new LiteralControl(cliente.Direccion));
                    HyperLink link = new HyperLink();

                    link.Text = "Editar";
                    link.NavigateUrl = "ListCliente.aspx?a=s&id=" + cliente.Id;
                    edit.Controls.Add(link);

                    HyperLink linkBorrar = new HyperLink();
                    linkBorrar.Text = "Borrar";
                    linkBorrar.NavigateUrl = "ListCliente.aspx?a=d&id=" + cliente.Id;
                    delete.Controls.Add(linkBorrar);

                    r.Cells.Add(delete);
                    r.Cells.Add(edit);
                    r.Cells.Add(id);
                    r.Cells.Add(name);
                    r.Cells.Add(ci);
                    r.Cells.Add(address);

                    table.Rows.Add(r);

                }
                
            }
            else { return null; }

            return table;
        }

        public static HtmlTable ListClientes(IList<Cliente> cli, List<int> cantidad)
        {
            throw new NotImplementedException();
        }
    }
}



